﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;

using LowLevelGraphics;
using LowLevelGraphics.Filter;
using LowLevelGraphics.CustomControls;

namespace ImageRecognition2.Action
{
    /// <summary>
    /// 
    /// </summary>
    public class ActionTemplateMatching : AbstractCommand
    {
        UnsafeBitmap bitmapTemplate = null;
        /// <summary>
        /// Initializes a new instance of the <see cref="ActionTemplateMatching"/> class.
        /// </summary>
        public ActionTemplateMatching()
        {
        }

        /// <summary>
        /// Runs the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void Run(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// Handles the SelectedEvent event of the SelectablePictureBox control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="LowLevelGraphics.CustomControls.PictureBoxSelectionEventArgs"/> instance containing the event data.</param>
        //protected void SelectablePictureBox_SelectedEvent(object sender, PictureBoxSelectionEventArgs e)
        //{
        //    bitmapTemplate = e.Image;
        //    UnsafeBitmap bitmap = MainFormSingleton.ActivePictureBox.BackgroundImage;
        //    SimpleTemplateMatching simpleMatching = new SimpleTemplateMatching(bitmapTemplate);
        //    simpleMatching.Execute(bitmap);
        //    bitmap.Dispose();
        //    Graphics g = Graphics.FromImage(bitmap.InternalBitmap);
        //    if (simpleMatching.SADPositions.Count > 0)
        //    {
        //        SADPosition position = simpleMatching.SADPositions[simpleMatching.SADPositions.Count - 1];
        //        g.DrawRectangle(Pens.Blue, position.BestCol, position.BestRow, bitmapTemplate.Width, bitmapTemplate.Height);
        //    }
        //    else
        //    {
        //        MessageBox.Show("Nothing found!", "Result");
        //    }

        //    //SelectablePictureBox.SelectedEvent -= new SelectablePictureBox.SelectedEventHandler(SelectablePictureBox_SelectedEvent);
        //}
    }
}
